package com.loveprogrammer.lowercode.dna.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @ClassName JsonUtils
 * @Description json工具类
 * @Author admin
 * @Date 2023/11/14 16:31
 * @Version 1.0
 */
public class JsonUtils {
    static final ObjectMapper objectMapper = new ObjectMapper();

    public static String pojoToJson(Object obj) throws JsonProcessingException {

        return objectMapper.writeValueAsString(obj);
    }

    public static <T> T jsonToPojo(String json,Class T) throws JsonProcessingException {
        return objectMapper.readValue(json, new TypeReference<T>() {});
    }
}
